import Vue from 'vue'
import App from './App'
import store from './store' // store
import plugins from './plugins' // plugins
import './permission' // permission
import hasPermi from './directives/hasPermi' // 引入权限指令
import { getDicts } from '@/api/system/dict/data'

Vue.use(plugins)

Vue.config.productionTip = false
Vue.prototype.$store = store
Vue.prototype.getDicts = getDicts
Vue.prototype.hasPermi = function (value) {
  const perms = this.$store.getters && this.$store.getters.permissions
  if (!perms) return false
  // 管理员万能权限
  if (perms.includes('*:*:*')) return true
  if (Array.isArray(value)) {
    return value.some((p) => perms.includes(p))
  } else if (typeof value === 'string') {
    return perms.includes(value)
  }
  return false
}
Vue.directive('hasPermi', hasPermi) // 全局注册权限指令

App.mpType = 'app'

const app = new Vue({
  ...App,
})

app.$mount()
